package com.huishu.order.config;

import cn.hutool.core.io.resource.ClassPathResource;
import com.github.wxpay.sdk.WXPayConfig;
import com.huishu.commons.constant.WxConstact;
import org.apache.poi.util.IOUtils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * @ClassName：MyWXConfig
 * @Author: ljj
 * @Date: 2022/6/24 16:22
 */
public class MyWXConfig implements WXPayConfig {
    private byte[] certData;
    public static final String APP_ID = WxConstact.APPID;
    public static final String KEY = WxConstact.KEY;
    public static final String MCH_ID = WxConstact.MCHID;

    public MyWXConfig() throws Exception {
        // 微信默认配置形式
        // springboot jar包形式 注意: 这里的证书放在resources/weixin 目录下 大家根据自己的情况修改
        ClassPathResource classPathResource = new ClassPathResource("weixin/apiclient_cert.p12");
        InputStream certStream = classPathResource.getStream();
        this.certData = IOUtils.toByteArray(certStream);
        certStream.read(this.certData);
        certStream.close();
    }

    @Override
    public String getAppID() {
        return WxConstact.APPID;
    }

    // parnerid，商户号
    @Override
    public String getMchID() {
        return WxConstact.MCHID;
    }

    @Override
    public String getKey() {
        return WxConstact.KEY;
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
